$(function(){
    var getParams = getArgs();
    window.currentHotel = getParams.hotel;
    var originalHref = $('#doc-header a').attr('href');
    $('#doc-header a').attr('href', originalHref + '?hotel=' + window.currentHotel);
    var mobileVal = getParams.val;
    var mobileCode = getParams.code;
    $('#verificateMobile').val(mobileVal);
    $('.areaCodeResetValue').text('+'+mobileCode);
    $('#mobileVerificateForm').inputValidate({
        submit: {
            query: '#sendAgain'
        },
        inputs: [{
            query: '#verificateMobile',
            regexp: window.commonRegexp.mobile.regexp,
            message: window.commonRegexp.mobile.message,
            emptyMessage: window.commonRegexp.mobile.emptyMessage
        }, {
            query: '#requestPassword',
            regexp: window.commonRegexp.password.regexp,
            message: window.commonRegexp.password.message,
            emptyMessage: window.commonRegexp.password.emptyMessage
        }]
    });
    $('#sendAgain').on('successSubmit.amos.inputValidate', function (e) {
        var submitBtn = $(this);
        var params = {};
        params.mobile = $('#verificateMobile').val();
        params.areaCode = mobileCode;
        toggleLoading(true);
        ajaxRequest('/Home/Public/forgetPasswordVcode', params, 'post', function (data) {
            toggleLoading(false);
            timeDisplay($('#sendAgain'), 60);
        }, function (error, obj, defaultErrorHandler) {
            toggleLoading(false);
            defaultErrorHandler(error, obj);
        }, submitBtn);
    });
    $('#mobileVerificateForms').inputValidate({
        submit: {
            query: '#submitMobileCode'
        },
        inputs: [{
            query: '#verificateMobile',
            regexp: window.commonRegexp.mobile.regexp,
            message: window.commonRegexp.mobile.message,
            emptyMessage: window.commonRegexp.mobile.emptyMessage
        }, {
            query: '#requestPassword',
            regexp: window.commonRegexp.password.regexp,
            message: window.commonRegexp.password.message,
            emptyMessage: window.commonRegexp.password.emptyMessage
        }, {
            query: '#requestMobileCode',
            regexp: window.commonRegexp.vcode.regexp,
            message: window.commonRegexp.vcode.message,
            emptyMessage: window.commonRegexp.vcode.emptyMessage
        }]
    });
    $('#submitMobileCode').on('successSubmit.amos.inputValidate', function (e) {
        var submitBtn = $(this);
        var params = {};
        params.mobile = $('#verificateMobile').val();
        params.password = $('#requestPassword').val();
        params.vcode = $('#requestMobileCode').val();
        params.areaCode = mobileCode;
        toggleLoading(true);
        ajaxRequest('/Home/Public/forgetPassword', params, 'post', function (data) {
            toggleLoading(false);
            formInlineTip(submitBtn, lang('resetSuccess'), 1);
            timeoutForward('/Home/PublicPage/login?hotel=' + window.currentHotel, 1000);
        }, function (error, obj, defaultErrorHandler) {
            toggleLoading(false);
            defaultErrorHandler(error, obj);
        }, submitBtn);
    });
    $('#mobileVerificateForm').bind('input propertychange',function(){
        var mobile = $('#verificateMobile').val();
        var $password = $('#requestPassword').val();
        var vcode = $('#requestMobileCode').val();
        if(mobile && vcode && $password){
            $('#submitMobileCode').attr('disabled', false);          
        }else{
            $('#submitMobileCode').attr('disabled', true);           
        }
    });
})
